home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / FASTCD09 / NON_TSR.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-02-07  |  9.7 KB  |  556 lines

  1. ; FastCD
  2. ; A small and fast Audio CD Player
  3. ;
  4. ;           Author: Johan Prins
  5. ; Internet address: jprins@dmrt.nl
  6.  
  7. .model small
  8. .code
  9. .286
  10.  
  11. org     100h
  12.  
  13. FastCD:
  14.  
  15. jmp start
  16.  
  17. NoMSCDEX    db    'FastCD requires MSCDEX.EXE',0Dh,0Ah,'$'
  18. Drive        db    ?
  19. Key        dw    ?
  20. data        dd    ?
  21. Tracks        dd    30 dup (?)
  22. DEC8        dd    ?
  23.  
  24. old_bar        db    104 dup (?)
  25.  
  26. BAR LABEL BYTE
  27.         DB      '█',3,'▓',115,'▒',115,'░'
  28.         DB      115,' ',121,'F',117,'a',117,'s',117,'t',117,'C',117,'D'
  29.         DB      117,' ',117,'▌',127,' ',127,'T',113,'r',113,'a',113,'c'
  30.         DB      113,'k',113,':',113,' ',113,' ',113,' ',113,' ',113,'·'
  31.         DB      113,' ',113,' ',113,' ',113,':',113,' ',113,' ',113,':'
  32.         DB      113,' ',113,' ',113,' ',127,'▌',127,' ',127,'V',117,'o'
  33.         DB      117,'l',117,':',117,' ',117,' ',117,' ',117,'∙',112,' '
  34.         DB      117,' ',117,' ',117,'░',115,'▒',115,'▓',115,'█',115
  35.  
  36. IOCTL        db    13 dup (0)    ;ReqHdr
  37.         db    0        ;media descriptor byte
  38.         dd    ?        ;transfer address
  39.         dw    ?        ;bytes to transfer
  40.         dw    0        ;starting sector
  41.         dd    0        ;pointer to req. volume
  42.  
  43. DiskInfo    db    10        ;control block code
  44.         db    ?        ;lowest track
  45.         db    ?        ;highest track
  46.         dd    ?        ;starting point of lead-out track
  47.  
  48. TrakInfo    db    11        ;control block code
  49.         db    ?        ;Track number
  50.         dd    ?        ;starting point of track
  51.         db    ?        ;Track control info
  52.  
  53. LocHead        db    1        ;control block code
  54.         db    0        ;addressing mode
  55.         dd    ?        ;location of drivehead
  56.  
  57. Play        db    13 dup (0)    ;request header
  58.         db    1        ;addressing mode
  59.         dd    ?        ;starting sector
  60.         dd    ?        ;number of sector to play
  61.  
  62. Stop        db    13 dup(0)    ;request header
  63.  
  64. AudInfo        db    3        ;control block code
  65.         db    ?        ;input channel for output channel 0
  66.         db    ?        ;volume for output channel 0
  67.         db    ?        ;input channel for output channel 1
  68.         db    ?        ;volume for output channel 1
  69.         db    ?        ;input channel for output channel 2
  70.         db    ?        ;volume for output channel 2
  71.         db    ?        ;input channel for output channel 3
  72.         db    ?        ;volume for output channel 3
  73.  
  74. QInfo        db    12        ;control block code
  75.         db    ?        ;Control and ADR byte
  76.         db    ?        ;Track #
  77.         db    ?        ;point/index
  78.         db    ?        ;Track min
  79.         db    ?        ;Track sec
  80.         db    ?        ;Track frame
  81.         db    ?        ;Track zero
  82.         db    ?        ;disk min
  83.         db    ?        ;disk sec
  84.         db    ?        ;disk frame
  85.  
  86. start:    
  87.     xor    bx,bx
  88.     mov    ax,1500h
  89.     int    2Fh            ;Get Nr of CD-ROM drives
  90.     cmp    bx,0            ;Nr of CD-ROM drives
  91.     jz    NoMSCD            ;0 -> driver not installed
  92.     mov    Drive,cl        ;CL contains 1st drive letter
  93.     jmp    Found
  94. NoMSCD:    mov    dx,offset NoMSCDEX
  95.     mov    ah,09h
  96.     int    21h
  97.     jmp    exit
  98.  
  99. Found:    mov    Drive,cl        ;CL contains 1st drive letter
  100.     call    getbar
  101.     lea    si,bar
  102.     call    putbar
  103.  
  104.     call    GetAudInfo
  105.     mov    dl,AudInfo[2]
  106.     shr    dl,2
  107.     mov    si,112
  108.     call    dec8out
  109.     mov    dl,AudInfo[4]
  110.     shr    dl,2
  111.     mov    si,118
  112.     call    dec8out
  113.  
  114.     call    GetDiskInfo        ;Get # of tracks
  115.     call    GetDiskInfo        ;Twice if first time failed...
  116.  
  117.     xor    ch,ch
  118.     mov    cl,DiskInfo[2]        ;Last track
  119.     cmp    cl,0            ;No tracks...exit
  120.     jne    Trks
  121.     jmp    exit
  122.  
  123. Trks:    call    GetTrackInfo
  124.     les    ax,dword ptr TrakInfo[2]
  125.     mov    di,cx
  126.     shl    di,2
  127.     mov    word ptr Tracks[di+2],es
  128.     mov    word ptr Tracks[di],ax
  129.     loop    Trks
  130.  
  131.     call    GetAudInfo
  132.  
  133. no_key:
  134.     call    QChannelInfo
  135.     mov    al,QInfo[2]        ;contains track nr. as it appears on CD
  136.                     ;AL needs conversion:
  137.     mov    dl,al
  138.     and    dl,000001111b        ;save low nibble
  139.     and    al,011110000b        ;save high nibble
  140.     shr    al,4
  141.     mov    bl,0Ah
  142.     mul    bl            ;multiply high nibble by 10
  143.     add    dl,al
  144.     xor    dh,dh
  145.     mov    di,dx
  146.     mov    si,70
  147.     call    dec8out
  148.     mov    dl,QInfo[4]
  149.     mov    si,80
  150.     call    dec8out
  151.     mov    dl,QInfo[5]
  152.     mov    si,86
  153.     call    dec8out
  154.     mov    dl,QInfo[6]
  155.     mov    si,92
  156.     call    dec8out
  157.  
  158.     mov    ah,01h
  159.     int    16h
  160.     jz    no_key            ;keypressed?
  161.     xor    ah,ah
  162.     int    16h
  163.     mov    key,ax            ;read scancode and char
  164.     
  165.     cmp    ah,19h            ; P or p    (play)
  166.     jne    Key_S
  167.     mov    di,1
  168.     call    StopCD
  169.     call    PlayCD
  170.     jmp    no_key
  171.  
  172. Key_S:    cmp    ah,1Fh            ;S or s     (stop)
  173.     jne    KeyPgUp
  174.     call    StopCD
  175.     jmp    no_key
  176.  
  177. KeyPgUp:cmp    ax,4900h        ;PgUp       (skip to next track)
  178.     jne    KeyPgDn
  179.     xor    cx,cx
  180.     mov    cl,byte ptr DiskInfo[2]
  181.     cmp    cx,di
  182.     jne    nomax
  183.     mov    di,0
  184.  nomax:    inc    di
  185.     call    StopCD
  186.     call    PlayCD
  187.     jmp    no_key
  188.  
  189. KeyPgDn:cmp    ax,5100h        ;PgDn       (skip to prev. track)
  190.     jne    Key_Up
  191.     cmp    di,1
  192.     jne    nomin
  193.     mov    cx,0001
  194.     add    cl,byte ptr DiskInfo[2]
  195.     mov    di,cx
  196.  nomin:    dec    di
  197.     call    StopCD
  198.     call    PlayCD
  199.     jmp    no_key
  200.  
  201. Key_Up: cmp    ax,4800h
  202.     jne    Key_Dn
  203.     add    AudInfo[2],4
  204.     add    AudInfo[4],4
  205.     call    PutAudInfo
  206.     mov    dl,AudInfo[2]
  207.     shr    dl,2
  208.     mov    si,112
  209.     call    dec8out
  210.     mov    dl,AudInfo[4]
  211.     shr    dl,2
  212.     mov    si,118
  213.     call    dec8out
  214.     jmp    no_key
  215.  
  216. Key_Dn: cmp    ax,5000h
  217.     jne    Key_Lf
  218.     sub    AudInfo[2],4
  219.     sub    AudInfo[4],4
  220.     call    PutAudInfo
  221.     mov    dl,AudInfo[2]
  222.     shr    dl,2
  223.     mov    si,112
  224.     call    dec8out
  225.     mov    dl,AudInfo[4]
  226.     shr    dl,2
  227.     mov    si,118
  228.     call    dec8out
  229.     jmp    no_key
  230.  
  231. Key_Lf: cmp    ax,4B00h
  232.     jne    Key_Rg
  233.     sub    AudInfo[4],4
  234.     call    PutAudInfo
  235.     mov    dl,AudInfo[4]
  236.     shr    dl,2
  237.     mov    si,118
  238.     call    dec8out
  239.     jmp    no_key
  240.  
  241. Key_Rg: cmp    ax,4D00h
  242.     jne    Key_ESC
  243.     sub    AudInfo[2],4
  244.     call    PutAudInfo
  245.     mov    dl,AudInfo[2]
  246.     shr    dl,2
  247.     mov    si,112
  248.     call    dec8out
  249.     jmp    no_key
  250.  
  251. Key_ESC:cmp    ax,011Bh        ;ESC (exit program)
  252.     je    exit
  253.     jmp    no_key
  254.  
  255.  
  256. exit:    
  257.     lea    si,old_bar
  258.     call    putbar
  259.     mov ax,4C00h
  260.     int 21h
  261.  
  262. ToCD    proc
  263.     push    ax
  264.     push    bx
  265.     push    cx
  266.     mov    ax,1510h
  267.     xor    ch,ch
  268.     mov    cl,Drive
  269.     les    bx,data
  270.     int    2Fh
  271.     pop    cx
  272.     pop    bx
  273.     pop    ax
  274.     ret
  275. endp    ToCD
  276.  
  277. GetDiskInfo    proc
  278.     mov    IOCTL[2],3        ;Command code
  279.  
  280.     mov    ax,cs
  281.     mov    word ptr IOCTL[16],ax    ;transfer address
  282.     mov    ax,offset DiskInfo
  283.     mov    word ptr IOCTL[14],ax    ;transfer address
  284.  
  285.     mov    IOCTL[18],7        ;bytes to transfer
  286.  
  287.     mov    ax,cs
  288.     mov    word ptr data[2],ax    ;address of IOCTL record
  289.     mov    ax,offset IOCTL
  290.     mov    word ptr data,ax    ;address of IOCTL record
  291.  
  292.     call    ToCD            ; Diskinfo[1,2] contains 1st & last trk
  293.  
  294.     xor    bx,bx
  295.     mov    bl, byte ptr DiskInfo[2]
  296.     mov    di,bx
  297.     inc    di
  298.     shl    di,2
  299.     les    ax,dword ptr DiskInfo[3]
  300.     mov    word ptr Tracks[di+2],es    ;end of disc
  301.     mov    word ptr Tracks[di],ax
  302.     ret
  303.  
  304. endp    GetDiskInfo
  305.  
  306. GetTrackInfo    proc
  307.     mov    IOCTL[2],3        ;command code
  308.     
  309.     mov    ax,cs
  310.     mov    word ptr IOCTL[16],ax    ;transfer address
  311.     mov    ax,offset TrakInfo
  312.     mov    word ptr IOCTL[14],ax    ;transfer address
  313.  
  314.     mov    IOCTL[18],7
  315.  
  316.     mov    TrakInfo[1],cl        ;contains track number
  317.  
  318.     mov    ax,cs
  319.     mov    word ptr data[2],ax    ;address of IOCTL record
  320.     mov    ax,offset IOCTL
  321.     mov    word ptr data,ax
  322.  
  323.     call    ToCD
  324.     ret
  325. endp    GetTrackInfo
  326.  
  327. PutAudInfo    proc            ;DL=left, DH=right volume
  328.     mov    IOCTL[2],12        ;command code
  329.     
  330.     mov    ax,cs
  331.     mov    word ptr IOCTL[16],ax    ;transfer address
  332.     mov    ax,offset AudInfo
  333.     mov    word ptr IOCTL[14],ax    ;transfer address
  334.  
  335.     mov    IOCTL[18],9
  336.  
  337.     mov    ax,cs
  338.     mov    word ptr data[2],ax    ;address of IOCTL record
  339.     mov    ax,offset IOCTL
  340.     mov    word ptr data,ax
  341.  
  342.     call    ToCD
  343.     ret
  344. endp    PutAudInfo
  345.  
  346. GetAudInfo    proc
  347.     mov    IOCTL[2],3        ;command code
  348.     inc    AudInfo[0]
  349.     
  350.     mov    ax,cs
  351.     mov    word ptr IOCTL[16],ax    ;transfer address
  352.     mov    ax,offset AudInfo
  353.     mov    word ptr IOCTL[14],ax    ;transfer address
  354.  
  355.     mov    IOCTL[18],9
  356.  
  357.     mov    ax,cs
  358.     mov    word ptr data[2],ax    ;address of IOCTL record
  359.     mov    ax,offset IOCTL
  360.     mov    word ptr data,ax
  361.  
  362.     call    ToCD
  363.     dec    AudInfo[0]
  364.     ret
  365. endp    GetAudInfo
  366.  
  367.  
  368. PlayCD    proc                ;DI must contain track number
  369.     push    di
  370.     mov    Play[2],132        ;command code
  371.  
  372.     shl    di,2
  373.  
  374.     les    bx,dword ptr Tracks[di]
  375.     mov    word ptr Play[16],es
  376.     mov    word ptr Play[14],bx
  377.     mov    cx,es
  378.  
  379.     call    RedBook2HSG
  380.     mov    bx,ax
  381.     mov    cx,dx
  382.     push    bx
  383.     push    cx
  384.     
  385.     mov    al,DiskInfo[2]        ;begin of last track
  386.     inc    al
  387.     xor    ah,ah
  388.     shl    ax,2            ;it are dwords
  389.     mov    di,ax
  390.  
  391.     call    RedBook2HSG
  392.  
  393.     pop    cx
  394.     pop    bx
  395.  
  396.     sub    ax,bx
  397.     jnc    @1
  398.     dec    dx
  399. @1:    sub    dx,cx
  400.     
  401.     mov    word ptr Play[20],dx
  402.     mov    word ptr Play[18],ax
  403.  
  404.     mov    ax,cs
  405.     mov    word ptr data[2],ax    ;address of Play record
  406.     mov    ax,offset Play
  407.     mov    word ptr data,ax
  408.  
  409.     call    ToCD
  410.  
  411.     pop    di
  412.     ret
  413. endp PlayCD
  414.  
  415. QChannelInfo    proc
  416.     mov    IOCTL[2],3        ;command code
  417.     
  418.     mov    ax,cs
  419.     mov    word ptr IOCTL[16],ax    ;transfer address
  420.     mov    ax,offset QInfo
  421.     mov    word ptr IOCTL[14],ax    ;transfer address
  422.  
  423.     mov    IOCTL[18],11
  424.  
  425.     mov    ax,cs
  426.     mov    word ptr data[2],ax    ;address of IOCTL record
  427.     mov    ax,offset IOCTL
  428.     mov    word ptr data,ax
  429.  
  430.     call    ToCD
  431.     ret
  432. endp    QChannelInfo
  433.  
  434.  
  435. StopCD proc
  436.     mov    Stop[2],133        ;command code
  437.     
  438.     mov    ax,cs
  439.     mov    word ptr data[2],ax    ;address of Stop record
  440.     mov    ax,offset Stop
  441.     mov    word ptr data,ax
  442.  
  443.     call    ToCD
  444.  
  445.     ret
  446. endp StopCD
  447.  
  448.  
  449. RedBook2HSG proc
  450.  
  451.     mov    ax,word ptr Tracks[di+2]    ;get high word
  452.     mov    cx,4500
  453.     mul    cx
  454.  
  455.     push    ax            ;put ax aside
  456.  
  457.     mov    al,byte ptr Tracks[di+1]
  458.     mov    cl,75
  459.     mul    cl
  460.     mov    bx,ax
  461.  
  462.     pop    ax            ;get ax back
  463.  
  464.     add    ax,bx
  465.     jnc    @2            ;carry? then decrease high word
  466.     inc    dx
  467. @2:    mov    cl,byte ptr Tracks[di]
  468.     xor    ch,ch
  469.     add    ax,cx
  470.     jnc    @3
  471.     inc    dx
  472. @3:    sub    ax,150
  473.     jnc    @4
  474.     dec    dx
  475. @4:    
  476.     ret
  477. endp RedBook2HSG
  478.  
  479. dec8out    proc
  480.  
  481.     push    di
  482.     mov    bx,0B800h
  483.     mov    ds,bx
  484.     xor    cx,cx            ; initialize a counter
  485.     mov    di,1            ; point to a buffer
  486.     mov    byte ptr DEC8[1],'0'    ; zero unused var's
  487.     mov    byte ptr DEC8[2],'0'    ;  "     "      "
  488.     mov    byte ptr DEC8[3],'0'    ;  "     "      "
  489.  
  490. dec8out1:
  491.     push    cx        ; save the count
  492.     mov    al,dl        ; AX has the numerator
  493.     xor    ah,ah        ; clear upper half
  494.     mov    cl,10        ; divisor of 10
  495.     div    cl        ; divide
  496.     mov    dl,al        ; get quotient
  497.     mov    al,ah        ; get remainder
  498.     add    al,30h        ; increase to ASCII
  499.     mov    byte ptr DEC8[di],al; put in tbuff
  500.     inc    di        ; point to next byte
  501.     pop    cx        ; restore count
  502.     inc    cx        ; count the digit
  503.     cmp    dl,0        ; done ?
  504.     jnz    dec8out1
  505.  
  506.     mov    al,byte ptr DEC8[2]
  507.     mov    ds:[si],al
  508.     mov    al,byte ptr DEC8[1]
  509.     mov    ds:[si+2],al
  510.     pop    di
  511.     ret            ; return
  512. dec8out    endp
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522. putbar    proc
  523.     push    di
  524.     cld
  525.     mov    dx,cs
  526.     mov    ds,dx
  527.     mov    dx,0B800h
  528.     mov    es,dx
  529. ;    lea    si,bar
  530.     mov    di,28
  531.     mov    cx,104
  532.     rep    movsb
  533.     pop    di
  534.     ret
  535. putbar    endp
  536.  
  537. getbar    proc
  538.     push    di
  539.     cld
  540.     mov    dx,cs
  541.     mov    es,dx
  542.     mov    dx,0B800h
  543.     mov    ds,dx
  544.     mov    si,28
  545.     lea    di,old_bar
  546.     mov    cx,104
  547.     rep    movsb
  548.     pop    di
  549.     ret
  550. getbar    endp
  551.  
  552. end FastCD
  553. end
  554.  
  555.  
  556.